﻿using BussinessObject.ObjectTwo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectHK3.App_Code;
using System.Data;
 
namespace ProjectHK3.Object_One
{
    public partial class Company : System.Web.UI.Page
    {
        B_LoadGidAD ex = new B_LoadGidAD();
        B_AdminDetail fx = new B_AdminDetail();
        B_Delete gx = new B_Delete();
        B_Check sx = new B_Check();
        DataTable tb = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            
                Label3.Text = fx.getCompany().ToString();
                _grwCompanies.DataSource = ex.loadCompany();
                _grwCompanies.DataBind();
            
            
        }

        protected void _lbtRemove_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
               
              Session["companyId"] = Convert.ToInt32(e.CommandArgument.ToString());
           
            }           
        }

        protected void _lbtViewDetails_Command(object sender, CommandEventArgs e)
        {
            Session["companyId"] = Convert.ToInt32(e.CommandArgument.ToString());
            Response.Redirect("../Object One/CompanyDetails.aspx");
        }

        protected void _grwCompanies_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

            tb = sx.CheckCom(int.Parse(Session["companyId"].ToString()));
                  if(tb.Rows.Count > 0)
                  {
                      Alert.Show("You can't Delete!!!");
                  }else
                  {
                      gx.DeleteCom(int.Parse(Session["companyId"].ToString()));                     
                      Response.Redirect("../Object One/Company.aspx");
                      Alert.Show("Delete Successful!!!");
                  }
        }   
        }
    }
